/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;

public class MyDocumentListener implements DocumentListener {
    private JTextPane texto;
    private DefaultStyledDocument sdoc;
    private MutableAttributeSet chars;
    private Style redstyle;
    
    public MyDocumentListener(JTextPane sTexto,DefaultStyledDocument doc,MutableAttributeSet charsx,Style red){
        texto=sTexto;
        sdoc=doc;
        chars=charsx;
        redstyle=red;
    }
    public void pintarlenguaje()
    {
      SimpleAttributeSet atributo = new SimpleAttributeSet();
      StyleConstants.setFontSize(atributo,14);
      StyleConstants.setForeground(atributo,Color.blue); 
      SimpleAttributeSet atributo2 = new SimpleAttributeSet();
      StyleConstants.setFontSize(atributo2,12);
      StyleConstants.setForeground(atributo2,Color.black);
      String soriginal=texto.getText();
      int post=0;
      post=post=soriginal.indexOf("int");
      while (post > -1) {
         texto.getStyledDocument().setCharacterAttributes(post,post+"int".length(),atributo,false);
         texto.setCharacterAttributes(atributo,false);
         texto.getStyledDocument().setCharacterAttributes(post+"int".length(),post+"int".length()+1,atributo2,false);
         texto.setCharacterAttributes(atributo2,false);
         post=soriginal.indexOf("int",post+1);
      }
    }
    public void insertUpdate(DocumentEvent e) {
           try{
            EventQueue.invokeLater(new Runnable()
             { 
              public void run() {
                 pintarlenguaje();
             }
            });
            }catch(Exception ex){
              System.out.println(ex.toString());
            }
    }
    public void removeUpdate(DocumentEvent e) {
          try{
            EventQueue.invokeLater(new Runnable()
             { 
              public void run() {
                 pintarlenguaje();
             }
            });
            }catch(Exception ex){
              System.out.println(ex.toString());
            }
    }
    public void changedUpdate(DocumentEvent e) {
         
    }
} 

